package main

import "fmt"

func main() {
	n := 5
	arr := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]int, n)
	}

	num := 1
	for layer := 0; layer < (n+1)/2; layer++ {
		// 从左到右
		for i := layer; i < n-layer; i++ {
			arr[layer][i] = num
			num++
		}
		// 从上到下
		for i := layer + 1; i < n-layer; i++ {
			arr[i][n-layer-1] = num
			num++
		}
		// 从右到左
		for i := n - layer - 2; i >= layer; i-- {
			arr[n-layer-1][i] = num
			num++
		}
		// 从下到上
		for i := n - layer - 2; i > layer; i-- {
			arr[i][layer] = num
			num++
		}
	}

	// 打印盘龙数组
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Printf("%3d ", arr[i][j])
		}
		fmt.Println()
	}
}
